package com.zhiyou100.review.day019.homework;

/**
 * @packageName: Homework2
 * @className: com.zhiyou100.review.day019.homework
 * @Description: TODO 3 模拟四个窗口卖一辆火车的100张票  卖票时打印票号
 * @author: yang
 * @date: 6/30/20
 */
public class Homework3 {
    public static void main(String[] args) {
        Window window = new Window();
        // 创建一个实现类对象
        Thread thread1 = new Thread(window, "一");
        Thread thread2 = new Thread(window, "二");
        Thread thread3 = new Thread(window, "三");
        Thread thread4 = new Thread(window, "四");
        // 创建5个线程，五个线程对象的线程完全一样
        thread1.start();
        thread2.start();
        thread3.start();
        thread4.start();

    }
}

class Ticket {

    static int number = 100;
    // 记录票数
}

class Window implements Runnable {
    @Override
    public void run() {
        while (Ticket.number > 0) {
            Ticket.number--;
            String message = Thread.currentThread().getName() + " 正在卖第 " + (100 - Ticket.number) + "张票";
            System.out.println(message);
        }
    }
}